package com.hci.leukemiaapp;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.TextView;

public class HomeScreenActivity extends Activity {
	
	static final String[] APMNTS = {
        "4PM Meet Dr. Phil", "5PM Take Meds", "6PM Gym", "7PM Meds Before Dinner", "NEXT EVENT", "NEXT EVENT", "NEXT EVENT"};
	
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.homescreen);
	    
	    ListView lv = (ListView) findViewById(R.id.HomeScreenList);
	    lv.setAdapter(new ArrayAdapter<String>(this, R.layout.home_list_item, APMNTS));
	    
	    GridView gridview = (GridView) findViewById(R.id.homeScreenGrid);
	    gridview.setAdapter(new TextAdapter(this));

	    gridview.setOnItemClickListener(new OnItemClickListener() {
	        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
	            Intent intent = new Intent(getApplicationContext(), LeukemiaApp.class);
	            intent.putExtra("tab", position+1);
	            startActivity(intent);
	        }
	    });

	}
	
	public class TextAdapter extends BaseAdapter {

	    private Context context;
	    private Integer[] textIDs = {
	    		R.id.WBCHomeButton,
	    		R.id.CalendarHomeButton,
	    		R.id.JournalHomeButton,
	    		R.id.PillBoxHomeButton,
	    		R.id.PhysiciansHomeButton,
	    		R.id.SocialHomeButton};

	    public TextAdapter(Context context) {
	        this.context = context;
	    }

	    public int getCount() {
	        return 6;
	    }

	    public Object getItem(int position) {
	        return null;
	    }

	    public long getItemId(int position) {
	        return 0;
	    }

	    public View getView(int position, View convertView, ViewGroup parent) {
	        TextView tv;
	        if (convertView == null) {
	        	LayoutInflater inflater =  (LayoutInflater)
	            	context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	        	View view = inflater.inflate(R.layout.home_menu_items, null);
	        	tv = (TextView) view.findViewById(textIDs[position]);
	            //tv = new TextView(context);
	            tv.setLayoutParams(new GridView.LayoutParams(110, 110));
	        }
	        else {
	            tv = (TextView) convertView;
	        }
	        return tv;
	    }
	}
}
